package com.tensquare.usercrawler.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.tensquare.usercrawler.pipeline.UserPipeline;
import com.tensquare.usercrawler.processor.UserPageProcessor;

import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.scheduler.Scheduler;

/**
 * 任务类
 * @author Johnny.Chen
 *
 */
@Component
public class UserTask {
	
	@Autowired
	private UserPageProcessor userPageProcessor;
	
	@Autowired
	private UserPipeline userPipeline;
	
	@Value("${tensquare.webmagic.urls}")
	private String urls;
	
	@Autowired
	private Scheduler scheduler;
	
	/**
	 * 任务
	 */
	@Scheduled(cron="${tensquare.webmagic.time1}")
	public void task1() {
		Spider.create(userPageProcessor)
			.addUrl(urls)
			.addPipeline(userPipeline)
			.setScheduler(scheduler)
			.start();
	}
}
